package com.jacen.fzxs.entity.webservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResponseState {

	private Integer code;
	private String description;
	private List<String> errorList;

	public static class CODE {
		public static final int SUCCESS = 0; // 成功
		public static final int PARAM_EXCEPTION = 1; // 参数传递异常
		public static final int DATABASE_EXCEPTION = 2; // 数据库操作异常
		public static final int PARAM_FORMAT_EXCEPTION = 3; // 参数传递格式不对，如：搜索内容有特殊符号
		public static final int SESSION_EXCEPTION = 4; // 用户会话异常
		public static final int PERMISSION_EXCEPTION = 5; // 权限异常
		public static final int XML_FORMAT_EXCEPTION = 6; // 报文格式错误
		public static final int UNKNOWN_EXCEPTION = 99; // 未知异常
	}

	public static Map<Integer, String> descriptionMap = new HashMap<Integer, String>();

	static {
		descriptionMap.put(CODE.PARAM_EXCEPTION, "参数传递异常");
		descriptionMap.put(CODE.DATABASE_EXCEPTION, "数据库操作异常");
		descriptionMap.put(CODE.PARAM_FORMAT_EXCEPTION, "参数传递格式不对");
		descriptionMap.put(CODE.SESSION_EXCEPTION, "用户会话异常常");
		descriptionMap.put(CODE.PERMISSION_EXCEPTION, "权限异常");
		descriptionMap.put(CODE.XML_FORMAT_EXCEPTION, "报文格式错误");
		descriptionMap.put(CODE.UNKNOWN_EXCEPTION, "未知异常");
	}

	public int getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
		this.description = descriptionMap.get(code);
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<String> getErrorList() {
		return errorList;
	}

	public void setErrorList(List<String> errorList) {
		this.errorList = errorList;
	}

	public void addError(String error) {
		if (errorList == null) {
			errorList = new ArrayList<String>();
		}
		errorList.add(error);
	}
}
